﻿using ComLib.ConfigService;
using LogLib;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

namespace PhotoCapturer
{
    public class PhotoCameraOption : IniConfigBase
    {
        public override string ConfigDirectory
        {
            get
            {
                string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
                directory = directory.Substring(6);
                return directory;
            }
        }

        public override string ConfigFilePath
        {
            get
            {
                if (string.IsNullOrEmpty(_strConfigPath))
                {
                    string className = this.GetType().Name;
                    _strConfigPath = Path.Combine(ConfigDirectory, className + ".ini");
                }
                return _strConfigPath;
            }
        }

        public PhotoCameraOption() : base()
        {
        }

        /// <summary>
        /// 镜头索引
        /// </summary>
        private int _camIndex = 0;
        public int CamIndex
        {
            get { return _camIndex; }
            set { _camIndex = value; }
        }

        /// <summary>
        /// 镜头名称
        /// </summary>
        private string _camName = "";
        public string CamName
        {
            get { return _camName; }
            set { _camName = value; }
        }

        /// <summary>
        /// 拍照时共享内存长度
        /// </summary>
        private int _shareMemoryDataLength = 5242880;
        public int ShareMemoryDataLength
        {
            get { return _shareMemoryDataLength; }
            set { _shareMemoryDataLength = value; }
        }

        public override bool Save()
        {
            base.Save();
            SaveField("CamIndex", _camIndex);
            SaveField("CamName", _camName);
            SaveField("ShareMemoryDataLength", _shareMemoryDataLength);           
            return true;
        }

        public override bool Load()
        {
            base.Load();
            try
            {
                _camIndex = LoadInt32Value("CamIndex");
                _camName = LoadStringValue("CamName");
                _shareMemoryDataLength = LoadInt32Value("ShareMemoryDataLength");
            }
            catch (Exception ex)
            {
                string strMsg = string.Format("配置文件{0}加载错误:\n\t{1}", ConfigFilePath, ex.Message);
                Log.WriteException(ex.ToString());
                return false;
            }
            return true;
        }

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder("高拍镜头选项: ");
            builder.Append("[镜头索引]:" + CamIndex.ToString());
            builder.Append("; [镜头索引]:" + CamName);
            builder.Append("; [拍照时共享内存长度]:" + ShareMemoryDataLength.ToString());
            return builder.ToString();
        }

    }
}
